package com.admin.service.impl;

import com.admin.common.enums.DeclareModuleEnum;
import com.admin.common.enums.DeclareScoreStatusEnum;
import com.admin.common.enums.DeclareTypeEnum;
import com.admin.common.enums.MemberLevelEnum;
import com.admin.common.exception.BizException;
import com.admin.common.util.BigDecimalUtil;
import com.admin.common.util.DateUtils;
import com.admin.domain.*;
import com.admin.mapper.*;
import com.admin.req.score.ScoreItemModuleReq;
import com.admin.req.score.ScoreItemReq;
import com.admin.req.score.ScoreReq;
import com.admin.service.*;
import com.admin.vo.ResultVO;
import com.admin.vo.declareDetail.retrunback.ReturnScoreModuleVO;
import com.admin.vo.declareDetail.score.ScoreListVO;
import com.admin.vo.declareDetail.score.ScoreSubModuleVO;
import com.admin.vo.declareDetail.score.SubModuleVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author yangzhongliang
 * @date 2022/05/16
 */
@Slf4j
@Service
public class DeclareScoreServiceImpl implements DeclareScoreService, InitializingBean {

    private final Set<String> scoreFieldsNameSet = new HashSet<>(16);

    @Autowired
    private DeclareMapper declareMapper;
    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private DeclareScoreMapper declareScoreMapper;
    @Autowired
    private DeclareScoreModuleMapper declareScoreModuleMapper;
    @Autowired
    private ScoreParamMapper scoreParamMapper;
    @Autowired
    private RegionsService regionsService;

    @Override
    public void afterPropertiesSet() throws Exception {
        scoreFieldsNameSet.addAll(
                Arrays.asList(new String[]{
                        "institutionScore","disasterPrepareScore","disasterFacilitiesScore",
                        "scienceScore","classicCaseScore","weatherBureauScore","upgradeScore"
                })
        );
    }

    /**
     * 主模块评分列表
     * @param moduleName
     * @param scoreListVOList
     * @return
     */
    @Override
    public List<ReturnScoreModuleVO> scoreModule(String moduleName, List<ScoreListVO> scoreListVOList) {
        if (CollectionUtils.isEmpty(scoreListVOList)) {
            return null;
        }
        List<ReturnScoreModuleVO> listVO = new ArrayList<>();
        for (ScoreListVO scoreListVO : scoreListVOList) {
            ReturnScoreModuleVO moduleVO = new ReturnScoreModuleVO();
            moduleVO.setUserLevel(scoreListVO.getScoreLevel());
            moduleVO.setUserLevelName(scoreListVO.getLevelName());
            if (moduleName.equals(DeclareModuleEnum.M10000.getName())) {
                moduleVO.setScore(scoreListVO.getInstitutionScore());
            } else if (moduleName.equals(DeclareModuleEnum.M20000.getName())) {
                moduleVO.setScore(scoreListVO.getDisasterPrepareScore());
            } else if (moduleName.equals(DeclareModuleEnum.M30000.getName())) {
                moduleVO.setScore(scoreListVO.getDisasterFacilitiesScore());
            } else if (moduleName.equals(DeclareModuleEnum.M40000.getName())) {
                moduleVO.setScore(scoreListVO.getScienceScore());
            } else if (moduleName.equals(DeclareModuleEnum.M50000.getName())) {
                moduleVO.setScore(scoreListVO.getClassicCaseScore());
            } else if (moduleName.equals(DeclareModuleEnum.M60000.getName())) {
                moduleVO.setScore(scoreListVO.getWeatherBureauScore());
            } else if (moduleName.equals(DeclareModuleEnum.M70000.getName())) {
                moduleVO.setScore(scoreListVO.getUpgradeScore());
            }
            listVO.add(moduleVO);
        }
        return listVO;
    }

    @Override
    public SubModuleVO subScoreModule(Integer declareId, String moduleName, List<ScoreParam> scoreParams) {
        SubModuleVO subModuleVO = new SubModuleVO();
        for (ScoreParam scoreParam : scoreParams) {
            if (moduleName.equals(scoreParam.getModuleName())) {
                subModuleVO.setModuleName(scoreParam.getModuleName());
                subModuleVO.setModuleScore(scoreParam.getModuleScore());
                subModuleVO.setScoreRule(scoreParam.getScoreRule());
                //子模块的打分信息
                List<ScoreSubModuleVO> subModuleVOS = declareScoreMapper.getSubScoreModule(declareId, moduleName);
                subModuleVO.setItems(subModuleVOS);
            }
        }
        return subModuleVO;
    }

    @Override
    public ResultVO save(Integer userId, ScoreReq scoreReq, String userLevel) {
        //查询当前登录用户所属社区
        AdminDO adminDO = adminMapper.selectByPrimaryKey(userId);
        if (Objects.isNull(adminDO)) {
            throw new BizException(-1, "登录信息已失效,请重新登录!");
        }
        Declare declare = declareMapper.selectByPrimaryKey(scoreReq.getDeclareId());
        if (Objects.isNull(declare)) {
            throw new BizException(-1, "申报信息不存在或已删除!");
        }

        Class<? extends ScoreReq> scoreReqClass = scoreReq.getClass();
        Field[] declaredFields = scoreReqClass.getDeclaredFields();

        List<Field> fieldList = Stream.of(declaredFields).filter(field -> scoreFieldsNameSet.contains(field.getName())).collect(Collectors.toList());
        List<ScoreItemReq> scoreItemList = fieldList.stream().map(field -> {
            try {
                field.setAccessible(true);
                return field.get(scoreReq);
            } catch (IllegalAccessException e) {
                log.error("invoke isFinishedScore method error! msg:{}", e);
                throw new BizException(-1, "服务端异常");            }
        }).filter(Objects::nonNull).map(v -> (ScoreItemReq) v).collect(Collectors.toList());

        //总分计算
        BigDecimal totalScore = scoreItemList.stream().map(v -> new BigDecimal(v.getTotalScore().doubleValue())).reduce(BigDecimal.ZERO, BigDecimal::add);

        //评分模块明细封装
        List<ScoreItemModuleReq> moduleReqs = new ArrayList<>();
        moduleReqs.addAll(scoreItemList.stream().map(v -> v.getItemScore()).flatMap(List::stream).collect(Collectors.toList()));
        List<DeclareScoreModule> moduleList = buildModuleList(moduleReqs);

        DeclareScore declareScore = declareScoreMapper.getByDeclareIdAndLevel(declare.getId(), userLevel);
        if (Objects.isNull(declareScore)) {
            saveDeclareScore(scoreReq, userLevel, adminDO, declare, totalScore, moduleList);
        } else {
            updateDeclareScore(declareScore, scoreReq, userLevel, adminDO, declare, moduleList);
        }

        return ResultVO.ok(true);
    }

    private void updateDeclareScore(DeclareScore declareScore, ScoreReq scoreReq, String userLevel, AdminDO adminDO, Declare declare, List<DeclareScoreModule> moduleList) {
        //评分主表
        //修改 - 不等于 null 修改
        if (Objects.nonNull(scoreReq.getInstitutionScore())) {
            declareScore.setInstitutionScore(scoreReq.getInstitutionScore().getTotalScore());
        }
        if (Objects.nonNull(scoreReq.getDisasterPrepareScore())) {
            declareScore.setDisasterPrepareScore(scoreReq.getDisasterPrepareScore().getTotalScore());
        }
        if (Objects.nonNull(scoreReq.getDisasterFacilitiesScore())) {
            declareScore.setDisasterFacilitiesScore(scoreReq.getDisasterFacilitiesScore().getTotalScore());
        }
        if (Objects.nonNull(scoreReq.getScienceScore())) {
            declareScore.setScienceScore(scoreReq.getScienceScore().getTotalScore());
        }
        if (Objects.nonNull(scoreReq.getClassicCaseScore())) {
            declareScore.setClassicCaseScore(scoreReq.getClassicCaseScore().getTotalScore());
        }
        if (Objects.nonNull(scoreReq.getWeatherBureauScore())) {
            declareScore.setWeatherBureauScore(scoreReq.getWeatherBureauScore().getTotalScore());
        }
        if (Objects.nonNull(scoreReq.getUpgradeScore())) {
            declareScore.setUpgradeScore(scoreReq.getUpgradeScore().getTotalScore());
        }

        ((DeclareScoreService)AopContext.currentProxy()).transactionUpdate(declare, declareScore, moduleList);
    }

    private void saveDeclareScore(ScoreReq scoreReq, String userLevel, AdminDO adminDO, Declare declare, BigDecimal totalScore, List<DeclareScoreModule> moduleList) {
        DeclareScore declareScore;
        //评分主表
        declareScore = new DeclareScore();
        declareScore.setDeclareId(declare.getId());
        declareScore.setCreateId(adminDO.getUserId());
        declareScore.setCreateMobile(adminDO.getMobile());
        declareScore.setCreateName(adminDO.getRealname());
        declareScore.setScoreLevel(userLevel);
        declareScore.setLevelName(regionsService.getDeclareRegionName(declare, userLevel));

        declareScore.setInstitutionScore(Objects.nonNull(scoreReq.getInstitutionScore()) ? scoreReq.getInstitutionScore().getTotalScore() : null);
        declareScore.setDisasterPrepareScore(Objects.nonNull(scoreReq.getDisasterPrepareScore()) ? scoreReq.getDisasterPrepareScore().getTotalScore() : null);
        declareScore.setDisasterFacilitiesScore(Objects.nonNull(scoreReq.getDisasterFacilitiesScore()) ? scoreReq.getDisasterFacilitiesScore().getTotalScore() : null);
        declareScore.setScienceScore(Objects.nonNull(scoreReq.getScienceScore()) ? scoreReq.getScienceScore().getTotalScore() : null);
        declareScore.setClassicCaseScore(Objects.nonNull(scoreReq.getClassicCaseScore()) ? scoreReq.getClassicCaseScore().getTotalScore() : null);
        declareScore.setWeatherBureauScore(Objects.nonNull(scoreReq.getWeatherBureauScore()) ? scoreReq.getWeatherBureauScore().getTotalScore() : null);
        declareScore.setUpgradeScore(Objects.nonNull(scoreReq.getUpgradeScore()) ? scoreReq.getUpgradeScore().getTotalScore() : null);
        declareScore.setTotalScore(totalScore.doubleValue());

        ((DeclareScoreService)AopContext.currentProxy()).transactionSave(declare, declareScore, moduleList);
    }


    private List<DeclareScoreModule> buildModuleList(List<ScoreItemModuleReq> moduleReqs) {
        if (CollectionUtils.isEmpty(moduleReqs) || moduleReqs.size() <= 0) {
            throw new BizException(-1, "你还没有选择需要打分的模块!");
        }
        //获取所有模块的评分规则
        List<String> moduleNames = moduleReqs.stream().map(e->e.getModuleName()).collect(Collectors.toList());
        Map<String, ScoreParam> ruleMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(moduleNames) && moduleNames.size() > 0) {
            List<ScoreParam> ruleList = scoreParamMapper.getByModuleNames(moduleNames);
            if (!CollectionUtils.isEmpty(ruleList)) {
                ruleMap = ruleList.stream().collect(Collectors.toMap(ScoreParam::getModuleName, Function.identity()));
            }
        }
        List<DeclareScoreModule> moduleList = new ArrayList<>();
        for (ScoreItemModuleReq moduleReq : moduleReqs) {
            ScoreParam scoreParam = ruleMap.get(moduleReq.getModuleName());
            if (Objects.isNull(scoreParam)) {
                throw new BizException(-1, "保存评分异常," + moduleReq.getModuleName() +",评分规则未配置或已删除!");
            }
            DeclareScoreModule scoreModule = new DeclareScoreModule();
            scoreModule.setModuleName(moduleReq.getModuleName());
            scoreModule.setModuleScore(moduleReq.getModuleScore());
            scoreModule.setModuleTotalScore(scoreParam.getModuleScore());
            scoreModule.setScoreRule(scoreParam.getScoreRule());
            scoreModule.setRemark(scoreParam.getRemark());
            moduleList.add(scoreModule);
        }
        return moduleList;
    }


    @Transactional
    @Override
    public void transactionSave(Declare declare, DeclareScore declareScore, List<DeclareScoreModule> scoreModuleList) {
        //评分主表
        declareScoreMapper.insertSelective(declareScore);
        //评分子模块表
        for (DeclareScoreModule scoreModule : scoreModuleList) {
            scoreModule.setDeclareScoreId(declareScore.getId());
            declareScoreModuleMapper.insertSelective(scoreModule);
        }
        //区县评分
        Declare updateDeclare = new Declare();
        updateDeclare.setId(declareScore.getDeclareId());
        if (declareScore.getScoreLevel().equals(MemberLevelEnum.AREA.getKey())) {
            if (isFinishedScore(declare, declareScore)) {
                updateDeclare.setScoreStatus(DeclareScoreStatusEnum.AREA_SUCCESS.getKey());
            } else {
                updateDeclare.setScoreStatus(DeclareScoreStatusEnum.AREA_PART_SUCCESS.getKey());
            }
            //分数
            updateDeclare.setAreaScore(declareScore.getTotalScore());
        } else if (declareScore.getScoreLevel().equals(MemberLevelEnum.CITY.getKey())) {
            if (isFinishedScore(declare, declareScore)) {
                updateDeclare.setScoreStatus(DeclareScoreStatusEnum.CITY_SUCCESS.getKey());
            } else {
                updateDeclare.setScoreStatus(DeclareScoreStatusEnum.CITY_PART_SUCCESS.getKey());
            }
            //分数
            updateDeclare.setCityScore(declareScore.getTotalScore());
        } else if (declareScore.getScoreLevel().equals(MemberLevelEnum.PROVINCE.getKey())) {
            if (isFinishedScore(declare, declareScore)) {
                updateDeclare.setScoreStatus(DeclareScoreStatusEnum.PROVINCE_SUCCESS.getKey());
            } else {
                updateDeclare.setScoreStatus(DeclareScoreStatusEnum.PROVINCE_PART_SUCCESS.getKey());
            }
            //分数
            updateDeclare.setProvinceScore(declareScore.getTotalScore());
        }
        declareMapper.updateByPrimaryKeySelective(updateDeclare);
    }


    @Transactional
    @Override
    public void transactionUpdate(Declare declare, DeclareScore declareScore, List<DeclareScoreModule> scoreModuleList) {
        //评分主表
        Double totalScore = 0d;
        if (Objects.nonNull(declareScore.getInstitutionScore())) {
            totalScore = BigDecimalUtil.add(totalScore, declareScore.getInstitutionScore());
        }
        if (Objects.nonNull(declareScore.getDisasterPrepareScore())) {
            totalScore = BigDecimalUtil.add(totalScore, declareScore.getDisasterPrepareScore());
        }
        if (Objects.nonNull(declareScore.getDisasterFacilitiesScore())) {
            totalScore = BigDecimalUtil.add(totalScore, declareScore.getDisasterFacilitiesScore());
        }
        if (Objects.nonNull(declareScore.getScienceScore())) {
            totalScore = BigDecimalUtil.add(totalScore, declareScore.getScienceScore());
        }
        if (Objects.nonNull(declareScore.getClassicCaseScore())) {
            totalScore = BigDecimalUtil.add(totalScore, declareScore.getClassicCaseScore());
        }
        if (Objects.nonNull(declareScore.getWeatherBureauScore())) {
            totalScore = BigDecimalUtil.add(totalScore, declareScore.getWeatherBureauScore());
        }
        if (Objects.nonNull(declareScore.getUpgradeScore())) {
            totalScore = BigDecimalUtil.add(totalScore, declareScore.getUpgradeScore());
        }
        declareScore.setTotalScore(totalScore);
        declareScoreMapper.updateByPrimaryKeySelective(declareScore);
        //评分子模块表
        for (DeclareScoreModule scoreModule : scoreModuleList) {
            //有可能修改，先删除 或新增
            declareScoreModuleMapper.deleteScoreModule(declareScore.getId(), scoreModule.getModuleName());
            scoreModule.setDeclareScoreId(declareScore.getId());
            declareScoreModuleMapper.insertSelective(scoreModule);
        }
        //区县评分
        Declare updateDeclare = new Declare();
        updateDeclare.setId(declareScore.getDeclareId());
        if (declareScore.getScoreLevel().equals(MemberLevelEnum.AREA.getKey())) {
            if (isFinishedScore(declare, declareScore)) {
                updateDeclare.setScoreStatus(DeclareScoreStatusEnum.AREA_SUCCESS.getKey());
            } else {
                updateDeclare.setScoreStatus(DeclareScoreStatusEnum.AREA_PART_SUCCESS.getKey());
            }
            //分数
            updateDeclare.setAreaScore(declareScore.getTotalScore());
        } else if (declareScore.getScoreLevel().equals(MemberLevelEnum.CITY.getKey())) {
            if (isFinishedScore(declare, declareScore)) {
                updateDeclare.setScoreStatus(DeclareScoreStatusEnum.CITY_SUCCESS.getKey());
            } else {
                updateDeclare.setScoreStatus(DeclareScoreStatusEnum.CITY_PART_SUCCESS.getKey());
            }
            //分数
            updateDeclare.setCityScore(declareScore.getTotalScore());
        } else if (declareScore.getScoreLevel().equals(MemberLevelEnum.PROVINCE.getKey())) {
            if (isFinishedScore(declare, declareScore)) {
                updateDeclare.setScoreStatus(DeclareScoreStatusEnum.PROVINCE_SUCCESS.getKey());
            } else {
                updateDeclare.setScoreStatus(DeclareScoreStatusEnum.PROVINCE_PART_SUCCESS.getKey());
            }
            //分数
            updateDeclare.setProvinceScore(declareScore.getTotalScore());
        }
        declareMapper.updateByPrimaryKeySelective(updateDeclare);
    }


    private Boolean isFinishedScore(Declare declare, DeclareScore declareScore) {
        //如果是提标升级 - 只判断自己
        if (declare.getDeclareType().equals(DeclareTypeEnum.UPGRADE.getKey())) {
            if (declareScore.getUpgradeScore() != null) {
                return true;
            }
        } else {
            Class<? extends DeclareScore> declareScoreClass = declareScore.getClass();
            Field[] declaredScoreFields = declareScoreClass.getDeclaredFields();

            List<Field> fieldList = Stream.of(declaredScoreFields).filter(field -> scoreFieldsNameSet.contains(field.getName())).collect(Collectors.toList());
            List<Double> scoreList = fieldList.stream().map(f -> {
                try {
                    f.setAccessible(true);
                    return f.get(declareScore);
                } catch (IllegalAccessException e) {
                    log.error("invoke isFinishedScore method error! msg:{}", e);
                    throw new BizException(-1, "服务端异常");
                }
            }).filter(Objects::nonNull).map(v -> (Double)v).collect(Collectors.toList());

            return fieldList.size() == scoreList.size();
        }
        return false;
    }


    @Override
    public List<ScoreListVO> findByDeclareId(Integer declareId) {
        Map<String,Object> params = new HashMap<>();
        params.put("declareId", declareId);
        List<DeclareScore> scoreList = declareScoreMapper.selectByMap(params);
        if (CollectionUtils.isEmpty(scoreList)) {
            return null;
        }
        List<ScoreListVO> listVOList = new ArrayList<>();
        for (DeclareScore declareScore : scoreList) {
            ScoreListVO listVO = new ScoreListVO();
            BeanUtils.copyProperties(declareScore, listVO);
            listVO.setCreateTimeStr(DateUtils.format(declareScore.getCreateTime(), DateUtils.DATE_PATTERN_TIME));
            listVOList.add(listVO);
        }
        return listVOList;
    }

    /**
     * 市级 - 批量赋分
     * @param adminDO
     * @param declare
     */
    @Transactional
    @Override
    public void cityBatchScore(AdminDO adminDO, Declare declare) {
        //判断是否已经评过
        DeclareScore areaScoreOld = declareScoreMapper.getByDeclareIdAndLevel(declare.getId(), MemberLevelEnum.CITY.getKey());
        if (!Objects.isNull(areaScoreOld)) {
            //已经评过了
            return;
        }
        //申报主表 评分
        Declare updateDeclare = new Declare();
        updateDeclare.setId(declare.getId());
        updateDeclare.setCityScore(declare.getAreaScore());
        updateDeclare.setScoreStatus(DeclareScoreStatusEnum.CITY_SUCCESS.getKey());
        declareMapper.updateByPrimaryKeySelective(updateDeclare);
        //模块评分主表
        //查询区县评分
        DeclareScore areaScore = declareScoreMapper.getByDeclareIdAndLevel(declare.getId(), MemberLevelEnum.AREA.getKey());
        if (!Objects.isNull(areaScore)) {
            //市级评分 - 复用区域评分
            DeclareScore cityScore = new DeclareScore();
            BeanUtils.copyProperties(areaScore, cityScore);
            cityScore.setId(null);
            cityScore.setScoreLevel(MemberLevelEnum.CITY.getKey());
            cityScore.setLevelName(regionsService.getDeclareRegionName(declare, MemberLevelEnum.CITY.getKey()));
            cityScore.setRemark("市级批量赋分");
            cityScore.setCreateId(adminDO.getUserId());
            cityScore.setCreateName(adminDO.getRealname());
            cityScore.setCreateMobile(adminDO.getMobile());
            cityScore.setCreateTime(null);
            cityScore.setModifyTime(null);
            declareScoreMapper.insertSelective(cityScore);

            //子模块评分表
            List<DeclareScoreModule> scoreModuleList = declareScoreModuleMapper.findDeclareScoreId(declare.getId());
            if (!CollectionUtils.isEmpty(scoreModuleList)) {
                for (DeclareScoreModule scoreModule : scoreModuleList) {
                    DeclareScoreModule newScoreModule = new DeclareScoreModule();
                    BeanUtils.copyProperties(scoreModule, newScoreModule);
                    newScoreModule.setId(null);
                    newScoreModule.setCreateTime(null);
                    newScoreModule.setModifyTime(null);
                    newScoreModule.setDeclareScoreId(cityScore.getId());
                    declareScoreModuleMapper.insertSelective(newScoreModule);
                }
            }
        }
    }

    /**
     * 省级 - 批量 - 评分
     * @param adminDO
     * @param declare
     */
    @Transactional
    @Override
    public void provinceBatchScore(AdminDO adminDO, Declare declare) {
        //判断是否已经评过
        DeclareScore areaScoreOld = declareScoreMapper.getByDeclareIdAndLevel(declare.getId(), MemberLevelEnum.PROVINCE.getKey());
        if (!Objects.isNull(areaScoreOld)) {
            //已经评过了
            return;
        }
        //申报主表 评分
        Declare updateDeclare = new Declare();
        updateDeclare.setId(declare.getId());
        //省级评分 == 市级评分
        updateDeclare.setProvinceScore(declare.getCityScore());
        updateDeclare.setScoreStatus(DeclareScoreStatusEnum.PROVINCE_SUCCESS.getKey());
        declareMapper.updateByPrimaryKeySelective(updateDeclare);
        //模块评分主表
        //查询市级评分
        DeclareScore cityScore = declareScoreMapper.getByDeclareIdAndLevel(declare.getId(), MemberLevelEnum.CITY.getKey());
        if (!Objects.isNull(cityScore)) {
            //市级评分 - 复用区域评分
            DeclareScore provinceScore = new DeclareScore();
            BeanUtils.copyProperties(cityScore, provinceScore);
            provinceScore.setId(null);
            provinceScore.setScoreLevel(MemberLevelEnum.PROVINCE.getKey());
            provinceScore.setLevelName(regionsService.getById(declare.getProvinceId()));
            provinceScore.setRemark("省级批量赋分");
            provinceScore.setCreateId(adminDO.getUserId());
            provinceScore.setCreateName(adminDO.getRealname());
            provinceScore.setCreateMobile(adminDO.getMobile());
            provinceScore.setCreateTime(null);
            provinceScore.setModifyTime(null);
            declareScoreMapper.insertSelective(provinceScore);

            //子模块评分表
            List<DeclareScoreModule> scoreModuleList = declareScoreModuleMapper.findDeclareScoreId(declare.getId());
            if (!CollectionUtils.isEmpty(scoreModuleList)) {
                for (DeclareScoreModule scoreModule : scoreModuleList) {
                    DeclareScoreModule newScoreModule = new DeclareScoreModule();
                    BeanUtils.copyProperties(scoreModule, newScoreModule);
                    newScoreModule.setId(null);
                    newScoreModule.setCreateTime(null);
                    newScoreModule.setModifyTime(null);
                    newScoreModule.setDeclareScoreId(cityScore.getId());
                    declareScoreModuleMapper.insertSelective(newScoreModule);
                }
            }
        }
    }

}
